package com.idol.logger

import com.idol.logger.core.IdolManager
import com.idol.logger.core.format.iface.IStackTraceFormat
import com.idol.logger.core.format.iface.IThreadFormat
import com.idol.logger.core.json.iface.IdolToJson
import com.idol.logger.core.printer.iface.IdolPrinter

object IdolLogger {

    /**
     * logger toggle.
     * @param debug true-open, false-close, default value false
     */
    fun setDebug(debug: Boolean) = IdolLogger.also { IdolManager.debug = debug }

    /**
     * object to json-string
     */
    fun setJsonParser(toJsonParser: IdolToJson) = IdolLogger.also { IdolManager.instance.messageFormat = toJsonParser }

    /**
     * object to json-string
     */
    fun setJsonParser(block: (List<Any>) -> String) = IdolLogger.also {
        IdolManager.instance.messageFormat = object : IdolToJson {
            override fun toJson(vararg data: Any) = block(data.asList())
        }
    }

    /**
     * set default tag.
     * @param tag default tag
     */
    fun setTag(tag: String) = IdolLogger.also { IdolManager.tag = tag }

    /**
     * thread toggle.
     * @param include true-open, false-close, default value false
     */
    fun setThread(include: Boolean) = IdolLogger.also { IdolManager.includeThread = include }

    /**
     * set stackTrace-depth for printer.
     * @param depth depth > 0 will be open, depth <= 0 close, default value depth = 0
     */
    fun setStackTraceDepth(depth: Int) = IdolLogger.also { IdolManager.stackTraceDepth = depth }

    fun setTreadFormat(format: IThreadFormat) = IdolLogger.also { IdolManager.instance.threadFormat = format }

    fun setStackTraceFormat(format: IStackTraceFormat) = IdolLogger.also { IdolManager.instance.stackTraceFormat = format }

    fun setPrinter(printer: IdolPrinter) = IdolLogger.also { IdolManager.instance.put(printer) }

    fun setPrinters(vararg args: IdolPrinter) = IdolLogger.also { IdolManager.instance.putAll(*args) }

    fun setPrinters(printers: List<IdolPrinter>) = IdolLogger.also { IdolManager.instance.putAll(printers) }

}